package com.iplant.pdm.serviceImpl.dao.fpc;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.dao.DBBaseDAO;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.pdm.service.po.bop.FPCRoutePartPoint;
import com.iplant.pdm.service.po.bop.partpoint.FPCRouteStep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.stream.Collectors;

@DBBaseDAO(FPCRoutePartPoint.class)
public class FPCRouteStepDAO extends BaseDAO {
    private static FPCRouteStepDAO Instance = null;

    private static Logger logger = LoggerFactory.getLogger(FPCRouteStepDAO.class);

    private FPCRouteStepDAO() {
        super("");
        this.Init();
    }

    public static FPCRouteStepDAO getInstance() {
        if (Instance == null)
            Instance = new FPCRouteStepDAO();
        return Instance;
    }

    public void DeleteList(BMSEmployee wLoginUser, List<FPCRouteStep> wFPCRoutePartPointDelete,
                           OutResult<Integer> wErrorCode) {
        List<String> wResult = new ArrayList<String>();
        try {
            if (wFPCRoutePartPointDelete == null || wFPCRoutePartPointDelete.size() <= 0) {
                return;
            }

            List<Integer> wIDList =
                    wFPCRoutePartPointDelete.stream().map(p -> p.ID).distinct().collect(Collectors.toList());

            String wSQL = StringUtils.Format("DELETE FROM {0}.`fpc_route_step` WHERE ID IN ({1});",
                    DBSchemas.PDM.getDBName(), StringUtils.Join(",", wIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wSQL = this.DMLChange(wSQL);

            this.update(wSQL, wParamMap);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }
}
